from db import db

class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(255), nullable=False)
    password = db.Column(db.String(255), nullable=False)
    phone = db.Column(db.String(255), nullable=False)
    role = db.Column(db.Integer, nullable=False)
    avatar = db.Column(db.String(255), nullable=False)
    hospital = db.Column(db.String(255), nullable=False)

    def __init__(self, username, password, phone, hospital=None,role=0,avatar="https://service-plat.oss-cn-beijing.aliyuncs.com/avatar.jpg"):
        self.username = username
        self.password = password
        self.phone = phone
        self.role = role
        self.hospital = hospital
        self.avatar = avatar

    def to_dict(self):
        return {
            'id': self.id,
            'username': self.username,
            'phone': self.phone,
            'role': self.role,
            'avatar': self.avatar,
            'hospital': self.hospital
        }